package com.nanyang.tms.mq.listener;

import com.nanyang.common.core.dict.CommonEnum;
import com.nanyang.common.core.domain.ApiResult;
import com.nanyang.tms.api.service.bill.BillRpcService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RocketMQMessageListener(topic = "billSolve",selectorExpression ="*", consumerGroup = "nanyang-tms-mq-consumer-billsolve-group",messageModel = MessageModel.CLUSTERING,consumeMode=ConsumeMode.ORDERLY)
public class BillSolveListener implements RocketMQListener<MessageExt>{
	@Reference(version = "1.0.0", timeout = 10000, check = false)
	private BillRpcService billRpcService;
	@Override
	public void onMessage(MessageExt message) {
		try {
			String body = new String(message.getBody());
			log.info("BillSolveListener inputParams:{}：" + body);
			ApiResult<Boolean> bill = billRpcService.syncSolveBill(body);
			if(CommonEnum.REQUEST_SUCCESS.getCode() != bill.getCode()){
				log.error("inputParams:{} and errorMessage:{}", new String(message.getBody()), bill.getMessage());
			}
		} catch (Exception e) {
			log.error("inputParams:{} and errorMessage:{}", new String(message.getBody()), e.getMessage(), e);
		}
	}

}
